import { Page, SysLogininfor, SysOperLog } from "@/interface/log";
import request from '../utils/request'
import { AxiosResponse } from "axios";

// 响应接口
export interface GetPageRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: Page<SysLogininfor[]>;
}

/** 
 * 分页查询
 * @param {string} current 
  * @param {string} pageSize 
  * @param {string} params 
  * @returns
 */
export function getLogPage(current: number, pageSize: number, params: string = ''): Promise<AxiosResponse<GetPageRes>> {
  return request.get(`/sys/logininfor/page?current=${current}&pageSize=${pageSize}&params=${params}`,{
    headers:{
      isToken: true
    }
  });
}

// 参数接口
export interface UpdateLogParams {
  /* */
  infoId?: number;

  /* */
  userName?: string;

  /* */
  ipaddr?: string;

  /* */
  status?: string;

  /* */
  msg?: string;

  /* */
  accessTime?: Record<string, unknown>;
}

// 响应接口
export interface UpdateLogRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: any;
}

/** 
 * 修改
 * @param {object} params SysLogininfor
 * @param {number} params.infoId 
 * @param {string} params.userName 
 * @param {string} params.ipaddr 
 * @param {string} params.status 
 * @param {string} params.msg 
 * @param {object} params.accessTime 
 * @returns
 */
export function updateLog(params: UpdateLogParams): Promise<AxiosResponse<UpdateLogRes>> {
  return request.post(`/sys/logininfor/update`, params,{
    headers:{
      isToken: true
    }
  });
}

// 响应接口
export interface DeleteLogRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: any;
}

/** 
 * 删除
 * @param {string} ids 
  * @returns
 */
export function deleteLog(ids: string): Promise<AxiosResponse<DeleteLogRes>> {
  return request.post(`/sys/logininfor/delete/${ids}`,null,{
    headers:{
      isToken: true
    }
  });
}

// 响应接口
export interface PageRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: Page<SysOperLog[]>;
}

/** 
 * 查询全部(分页)
 * @param {string} current 
  * @param {string} pageSize 
  * @returns
 */
export function OperLogPage(current: number, pageSize: number,params = ''): Promise<AxiosResponse<PageRes>> {
  return request.get(`/sys/log/page?current=${current}&pageSize=${pageSize}&params=${params}`,{
    headers:{
      isToken: true
    }
  });
}

// 响应接口
export interface UpdateOperLogRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: any;
}

/** 
 * 修改
 * @param {object} params SysOperLog
 * @returns
 */
export function updateOperLog(params: SysOperLog): Promise<AxiosResponse<UpdateOperLogRes>> {
  return request.post(`/sys/log/update`, params, {
    headers:{
      isToken: true
    }
  });
}

// 参数接口

// 响应接口
export interface DeleteOperLogRes {
  /* */
  code: number;

  /* */
  msg: string;

  /* */
  data: any;
}

/** 
 * 删除
 * @param {array} params integer
 * @returns
 */
export function deleteOperLog(ids: string): Promise<AxiosResponse<DeleteOperLogRes>> {
  return request.post(`/sys/log/delete/${ids}`, null, {
    headers:{
      isToken: true
    }
  });
}